package com.leetcode;

import com.leetcode.common.ListNode;

/**
 * 83. 删除排序链表中的重复元素
 */
public class Solution83 {

    public ListNode deleteDuplicates1(ListNode head) {
        ListNode cur = head;
        ListNode pre = new ListNode(-101, null);
        while (cur != null) {
            if (pre.val != cur.val) {
                pre = cur;
            } else {
                pre.next = cur.next;
            }
            cur = cur.next;
        }
        return head;
    }

    public ListNode deleteDuplicates(ListNode head) {
        if (head == null) {
            return null;
        }
        ListNode cur = head;
        while (cur.next != null) {
            if (cur.val == cur.next.val) {
                cur.next = cur.next.next;
            } else {
                cur = cur.next;
            }
        }
        return head;
    }

}
